package jiali.controller;


import jiali.model.Standard;
import jiali.model.vo.StandardVO;
import jiali.service.CommonService;
import jiali.service.UploadService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hello")
public class HelloWorldController {

    @Autowired
    private UploadService uploadService;

    @Autowired
    private CommonService commonService;

    @RequestMapping("/{id}")
    public String hello(@PathVariable Integer id){
        System.out.println("hello world..");
        return "OK";
    }

    @RequestMapping(value = "/api/listEntryStandardization")
    public String listEntryStandardization(@RequestBody StandardVO dataList) {
        commonService.setStandardization(dataList);
        return null;
    }

    @RequestMapping(value = "/api/upload")
    public String upload(@RequestParam MultipartFile file, @RequestParam String vendor,
                         @RequestParam String bizType) {
        if (file.isEmpty()) {
            return "file is empty";
        }
        String fileName = file.getOriginalFilename();
        if (StringUtils.isNotBlank(fileName) && !".xlsx".equals(fileName.substring(fileName.length() - 5))) {
            return "format error";
        }
        System.out.println(vendor);
        System.out.println(bizType);
        uploadService.upload(file);
        return "success";
    }


    @RequestMapping(value = "/test1")
    public void test1(@RequestParam String[] dateStr) {
        for (String s : dateStr) {
            System.out.println(s);
        }
    }

    @RequestMapping(value = "/test2")
    public void test2(@RequestBody Map hashMap) {
        System.out.println(hashMap.get("vendor"));
        System.out.println(hashMap.get("bizType"));
    }
}
